<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>消息推送</title>
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="component/pear/css/pear.css" />
	<link rel="stylesheet" href="admin/css/other/login.css" />
</head>
<!-- 代 码 结 构 -->

<body background="admin/images/background.svg" style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);">
		<div class="layui-form-item">
			<img class="logo" src="admin/images/logo.png" />
			<div class="title">消息推送</div>
			<div class="desc">
				多 平 台 消 息 推 送
			</div>
		</div>
		<div class="layui-form-item">
			<input id="username" placeholder="请输入账号或手机号" lay-verify="required" hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input type="password" id="password" placeholder="请输入密码" lay-verify="required" hover class="layui-input"
				lay-affix="eye" />
		</div>
		<div class="layui-form-item">
			<button type="button" id="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
				登 入
			</button>
		</div>
	</form>
	<!-- 资 源 引 入 -->
	<script src="component/com/api.js"></script>
	<script src="component/layui/layui.js"></script>
	<script src="component/pear/pear.js"></script>
	<script>
		layui.use(['form', 'button', 'popup', "jquery"], function () {
			var form = layui.form;
			var button = layui.button;
			var popup = layui.popup;
			var $ = layui.jquery;
			let API_BASE_URL = apiConfig.baseUrl;
			// 登 录 提 交
			form.on('submit(login)', function (data) {
				button.load({
					elem: '.login',
					time: 1500
				})
				let username = $("#username").val()
				let password = $("#password").val()

				$.ajax({
					url: apiConfig.baseUrl + '/common/login/',
					type: 'POST',
					data: {
						username: username,
						password: password
					},
					dataType: 'json',
					success: function (res) {
						console.log('res====', res)
						console.log('token====', res.token)
						if (res.code === 200){
							layer.msg("认证成功", {
							icon: 1,
							time: 1000},function(){
								localStorage.setItem('token',res.token)
								localStorage.setItem('user_info',JSON.stringify(res.user_info))
								sessionStorage.setItem('token',res.token)
								sessionStorage.setItem('user_info',JSON.stringify(res.user_info))
								location.href = "index.html"
							})
						}else{
							layer.msg(res.msg, {
								icon: 2,
								time: 3000
							})
						}
					},
					error: function (err) {
						console.log("API请求错误")
						layer.msg(err.msg, {icon: 2,time: 3000})
					}
				})
				return false;
			});
		})
	</script>
</body>

</html>